package cn.stimd.spring.aop.framework;

import java.lang.reflect.Proxy;

/**
 * Created by Stimd
 * 项目地址：https://gitee.com/stimd/spring-wheel
 * 公众号：Java编程探微
 */
public class AopProxyUtils {

    //设置被代理的接口
    public static Class<?>[] completeProxiedInterfaces(AdvisedSupport advised) {
        Class<?>[] specifiedInterfaces = advised.getProxiedInterfaces();
        if (specifiedInterfaces.length == 0) {
            Class<?> targetClass = advised.getTargetClass();

            if (targetClass.isInterface()) {
                advised.setInterfaces(targetClass);
            }
            else if (Proxy.isProxyClass(targetClass)) {
                advised.setInterfaces(targetClass.getInterfaces());
            }
            specifiedInterfaces = advised.getProxiedInterfaces();
        }
        return specifiedInterfaces;
    }
}
